package com.atguigu.controller;

import com.atguigu.base.BaseController;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {

    @DubboReference
    private DictService dictService;

    //跳转到数据字典的首页
    @GetMapping
    public String index() {
        return "dict/index";
    }

    //异步请求，显示数据字典
    @GetMapping("/findZnodes")
    @ResponseBody
    public Result findByParentById(@RequestParam(value = "id", defaultValue = "0") Long id) {
        //调用业务层方法以id的值作为parentId查询子节点列表
        List<Map<String, Object>> znodes = dictService.findZnodes(id);
        return Result.ok(znodes);
    }

    //异步请求，根据区域id查询小区信息
    @GetMapping("/findListByParentId/{parentId}")
    @ResponseBody
    public Result findListByParentId(@PathVariable Long parentId) {
        //调用业务层方法根据parentId查询子节点列表
        List<Dict> dictList = dictService.findListByParentId(parentId);
        return Result.ok(dictList);
    }

}
